package com.lifesaftypower.adapter;

import java.util.List;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import com.lifesaftypower.activity.R;
import com.lifesaftypower.entity.Product;

public class ProductAdapter extends ArrayAdapter<Product> {
	private List<Product> _item;

	public ProductAdapter(Context context, int textViewResourceId,
			List<Product> objects) {
		super(context, textViewResourceId, objects);
		_item = objects;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		View v = convertView;
		Log.i("Product List", Integer.toString(position));
		if (v == null) {
			LayoutInflater vi = (LayoutInflater) getContext().getSystemService(
					Context.LAYOUT_INFLATER_SERVICE);
			v = vi.inflate(R.layout.product_detail_list_item, null);
			
			TextView tv = (TextView)v.findViewById(R.id.tvProductName);
			if(tv != null) {
				tv.setText(_item.get(position).getName());
			}
			
		}

		return v;
	}
}
